/*
** init_socket.c for  in /home/faye_m//zappy
** 
** Made by mouhamed faye
** Login   <faye_m@epitech.net>
** 
** Started on  Tue Jun 14 20:22:53 2011 mouhamed faye
** Last update Thu Jun 16 20:31:16 2011 mouhamed faye
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "server.h"

void	init_socket(Vars_Packages *var, int port)
{
  memset (var->buffer,'\0', MAXBUFFERSIZE);
  memset (var->tabsockfd,'\0', FD_SETSIZE);  
  var->sin_size = sizeof(struct sockaddr_in);
  var->sockmax = 0;
  var->is_gaming  = 1;
  var->reused_socket = 1;
  var->sockfd = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP);
  setsockopt(var->sockfd, SOL_SOCKET,SO_REUSEADDR,&var->reused_socket,
    sizeof(int));
  var->my_addr.sin_family = AF_INET;
  var->my_addr.sin_port = ntohs(port);
  var->my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  bind(var->sockfd,(struct sockaddr *) &var->my_addr,
       sizeof(var->my_addr));
       
  listen(var->sockfd, 42);
  printf("Zappy Server Waiting for connexion ...\n");
}
